package coint.btc.dao.btcuser.impl;

import org.hibernate.type.StandardBasicTypes;
import org.springframework.stereotype.Repository;

import coint.btc.base.dao.BaseDAO;
import coint.btc.dao.btcuser.BtcUserCustom;
import coint.btc.dto.BtcUserDto;
import coint.btc.pojo.BtcUser;
/**
 * btc 用户自定义实现
 * @author lt
 *
 */
@Repository
public class BtcUserJpaImpl extends BaseDAO implements BtcUserCustom {

	@Override
	public BtcUser findUser(BtcUserDto user) {
		StringBuilder sql=new StringBuilder("select * from yonghu where Tongguo=2 and (Shouji=:paramName");
		sql.append(" or nicheng=:paramName or idcard=:paramName ) ");
		sql.append(" and Mima =:password ");
		return (BtcUser) getSession().createSQLQuery(sql.toString()).addEntity(BtcUser.class)
				.setParameter("paramName", user.getParamName(),StandardBasicTypes.STRING)
				.setParameter("password", user.getMima(),StandardBasicTypes.STRING).uniqueResult();
		
	}

	@Override
	public Integer checkIsNotRepeat(BtcUserDto user) {
		String sql="select count(1) from yonghu where shouji=:phone or nicheng=:nickName or idCard=:idCard ";
		int count=((Number)getSession().createSQLQuery(sql)
				.setParameter("phone", user.getShouji(),StandardBasicTypes.STRING)
				.setParameter("nickName", user.getNicheng(),StandardBasicTypes.STRING)
				.setParameter("idCard", user.getIdCard(),StandardBasicTypes.STRING).uniqueResult()).intValue();
		return count;
	}
      
}
